package com.lanchuan.soft.utils;

import lombok.extern.log4j.Log4j2;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

@Log4j2
public class CommonUtils {

    public static String createKeyId() {
        int min = 10000;
        int max = 100000;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String datetime = sdf.format(new Date());
        StringBuilder sb = new StringBuilder();
        sb.append(datetime);
        int current = (int) Math.floor(Math.random() * (max - min) + min);
        sb.append(current);
        return sb.toString();
    }

    public static String createUploadPath() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        return sdf.format(new Date());
    }

    public static String getRandomNumCode(int number) {
        StringBuilder codeNum = new StringBuilder();
        int[] numbers = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
        Random random = new Random();
        for (int i = 0; i < number; i++) {
            int next = random.nextInt(10000);//目的是产生足够随机的数，避免产生的数字重复率高的问题
            codeNum.append(numbers[next % 10]);
        }
        return codeNum.toString();
    }
}
